#include "stm32f10x.h" // Device header
#include "Serial.h"
#include "LED.h"
#include "sht30.h"
#include "MS5611.h"
#include "myiic.h"

int type = 1;
float temperature, humidity;
extern uint32_t yali;
extern double MSbaro_h;
extern uint64_t TEMP;

int main(void)
{
    LED_Init();
    i2c_init();
    IIC_Init();
    MS5611_init();
    // OLED_Init();
    NVIC_Config();
    USART_1_Config();
    USART_2_Config();
    // OLED_ShowString(1, 1, "Hello World!");
    while (1) {
        if (Serial2_RxFlag == 1) {
            if (Serial2_RxPacket[0] == '1') {
                type = 1;
            } else {
                type = 2;
            }
            Serial2_RxFlag = 0;
        }
        if (Serial_RxFlag == 1 && type == 1) {
            GPIO_ResetBits(GPIOB, GPIO_Pin_5);
            for (int i = 0; i <= 31; i++) {

                Serial_SendByte(USART2, Serial_RxPacket[i]);
            }
            if (read_sht30_data(&temperature, &humidity) == 0) {
                Serial_SendNumber(USART2, temperature * 100, 4);
                Serial_SendNumber(USART2, humidity * 100, 4);
            }
            // MS561101BA_RESET();
            MS561101BA_getPressure();
            MS561101BA_GetTemperature();
            Serial_SendNumber(USART2, yali, 8);
            Serial_SendNumber(USART2, TEMP, 4);
            Serial_SendString(USART2, "\r\n");
            Serial_RxFlag = 0;
        } else {
            GPIO_SetBits(GPIOB, GPIO_Pin_5);
        }
    }
}
